<script setup>
import {ref} from "vue";
import {ElMessage} from "element-plus";
import axios from "axios";
import qs from "qs";
import router from "@/router";

const weibo=ref({content:""});
const post=()=>{
  let user=localStorage.user?JSON.parse(localStorage.user):null;
  weibo.value.userId=user.id;
  let data=qs.stringify(weibo.value);
  axios.post('http://localhost:8081/v1/weibos/add-new',data)
      .then(
          (response)=>{
            if (response.data.code==2001){
              ElMessage.success("发布完成！");
              router.push('/');
            }else {
              ElMessage.error(response.data.msg);
            }
          }
      );
}
</script>

<template>
<h1>发微博</h1>
  <el-input placeholder="说点什么。。。" v-model="weibo.content"></el-input>
  <el-button @click="post()">发布</el-button>
</template>
